package se.webbzon.boltzmann.editor.component.sequence.panel;

import java.awt.GridLayout;
import java.util.Collection;

import javax.swing.JLabel;
import javax.swing.JTextField;

import se.webbzon.boltzmann.game.sequence.builder.assignment.AssignmentRow;

public class AssignmentRowPanel extends AbstractRowPanel {
	
	// Auto generated serial version UID
	private static final long serialVersionUID = 4072351470273197624L;
	
	// The text fields of this panel
	private final JTextField variableInput, expressionInput;
	
	/*============================================================
	Constructors
	============================================================*/

	/** Creates a new assignment row panel. **/
	public AssignmentRowPanel(AssignmentRow row) {
		super(row);
		setLayout(new GridLayout(2,2));
		add(new JLabel("Variable name"));
		variableInput = new JTextField(row.getVariable());
		add(variableInput);
		add(new JLabel("Expression"));
		expressionInput = new JTextField(row.getExpression());
		add(expressionInput);
	}
	
	/*============================================================
	Public Methods
	============================================================*/

	@Override public boolean apply(Collection<String> errorMessages) {
		AssignmentRow row = (AssignmentRow) getSequenceRow();
		row.setVariable(variableInput.getText());
		row.setExpression(expressionInput.getText());
		return true;
	}

}
